/**
 * 
 */
package com.xb.cloud.front.client;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.xb.cloud.front.common.FrontShopService;
import com.xb.cloud.gateway.client.Adapter;
import com.xb.cloud.gateway.client.AdapterContext;
import com.xb.cloud.gateway.client.ReturnCodes;
import com.xb.cloud.gateway.client.ReturnUtils;
import com.xb.cloud.gateway.client.RtnInfo;

/**
 * 买家端店铺服务
 * 
 * @author kexue
 *
 */
@Component
public class FrontShopAdapter extends Adapter {

	@Autowired
	FrontShopService frontShopService;

	@Override
	public RtnInfo execute(String urlPath, Boolean isLogined, Map<String, String> bizInfo,
			AdapterContext adapterContext) {

		if ("/h5/front/shop/getShopBoById".equalsIgnoreCase(urlPath)) {
			Long shopId = null;
			try {
				shopId = Long.valueOf(bizInfo.get("shopId"));
				if (shopId == null) {
					return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
				}
			} catch (Exception e) {
				e.printStackTrace();
				return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
			}

			RtnInfo rtnInfo = frontShopService.getShopBoById(shopId);
			return rtnInfo;
		}else if ("/h5/front/shop/getShopNavicationGroup".equalsIgnoreCase(urlPath)) {
			//getShopNavicationGroup
			Long shopId = null;
			try {
				shopId = Long.valueOf(bizInfo.get("shopId"));
				if (shopId == null) {
					return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
				}
			} catch (Exception e) {
				e.printStackTrace();
				return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
			}
			RtnInfo rtnInfo =  frontShopService.getShopNavicationGroup(shopId);
			return rtnInfo;
		}else if ("/h5/front/shop/getShopPromotionSkuList".equalsIgnoreCase(urlPath.trim())) {
			//获取当前店铺推荐
			Long shopId = null;
			try {
				shopId = Long.valueOf(bizInfo.get("shopId"));
				if (shopId == null) {
					return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
				}
			} catch (Exception e) {
				e.printStackTrace();
				return ReturnUtils.error(ReturnCodes.PARAM_INVALID);
			}
			RtnInfo result=frontShopService.getShopPromotionSkuList(shopId);
			return result;
		}
		return null;
	}

	@Override
	public String getUrlMappingPath() {
		return "/h5/front/shop";
	}

}
